Skip to content

Fix code scanning alert no. 1: Arbitrary file access during archive extraction ("Zip Slip") #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

ahmedsza
Copy link
Owner

Fixes https://github.com/ahmedsza/TechExcel-Accelerate-developer-productivity-with-GitHub-Copilot-and-Dev-Box/security/code-scanning/1

To fix the problem, we need to ensure that the file paths constructed from zip archive entries are validated to prevent writing files to unexpected locations. The steps to fix this are:

  1. Use Path.Combine(destinationDirectory, entry.FullName) to determine the raw output path.
  2. Use Path.GetFullPath(..) on the raw output path to resolve any directory traversal elements.
  3. Use Path.GetFullPath(destinationDirectory + Path.DirectorySeparatorChar) to determine the fully resolved path of the destination directory.
  4. Validate that the resolved output path StartsWith the resolved destination directory, aborting if this is not true.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…xtraction ("Zip Slip")

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ahmedsza ahmedsza marked this pull request as ready for review October 30, 2024 12:28
@ahmedsza ahmedsza merged commit b523934 into main Oct 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant